﻿g.tool = g.tool || {};
g.tool.menu = {
    "getEle": function () {
        return document.getElementById("menu_001");
    },
    "insertItem": function (p_index, p_content) {
        var tmp_container = document.createElement("td");
        tmp_container.innerHTML = p_content;
        var tmp = g.tool.menu.getEle();
        var tmpEle;
        if (tmp.children[0].tagName == "TBODY") {
            tmpEle = tmp.children[0].children[0];
        } else {
            tmpEle = tmp.children[0];
        }
        if(p_index == 0){
            return tmpEle.appendChild(tmp_container);
        }else{
            return tmpEle.insertBefore(tmp_container, tmpEle.children[p_index]);
        }
    },
    "removeItemByIndex": function (p_index) {
        var tmp = g.tool.menu.getEle();
        var tmpEle;
        if (tmp.children[0].tagName == "TBODY") {
            tmpEle = tmp.children[0].children[0];
        } else {
            tmpEle = tmp.children[0];
        }
        tmpEle.removeChild(tmpEle.children[p_index]);
    },
    "updateItem": function (p_index, p_content) {
        var tmp = g.tool.menu.getEle();
        var tmpEle;
        if (tmp.children[0].tagName == "TBODY") {
            tmpEle = tmp.children[0].children[0];
        } else {
            tmpEle = tmp.children[0];
        }
        tmpEle.children[p_index].innerHTML = p_content;
    }
};